package com.lanou.elh.sysmanage.authority_management.web.controller;

import com.lanou.elh.sysmanage.authority_management.common.Result;
import com.lanou.elh.sysmanage.authority_management.common.ResultUtil;
import com.lanou.elh.sysmanage.authority_management.entity.Permission;
import com.lanou.elh.sysmanage.authority_management.service.PermissionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    @GetMapping("/user/selectAllPermission")
    @ApiOperation(value = "查看所有权限节点")
     public Result<List<Permission>> selectAllPermissionService(){
        List<Permission> permissionList = permissionService.selectAllPermission();
        return new ResultUtil<List<Permission>>().setData(permissionList);
    }

    @DeleteMapping("/admin/deletePermissonById")
    @ApiOperation(value = "通过id删除单条权限节点")
    public Result deletePermissonById(Integer id){
        permissionService.deletePermissonById(id);
        return new ResultUtil<>().setData("删除成功");
    }


    @DeleteMapping("/admin/deleteManyPermissonById")
    @ApiOperation(value = "批量删除权限节点")
    public Result deletePermissonById(Integer[] id){
        permissionService.deleteAllPermissonById(id);
        return new ResultUtil<>().setData("删除成功");
    }


    @PutMapping("/admin/updatePermissonById")
    @ApiOperation(value = "通过id修改单条权限节点")
    public Result updatePermissonById(Permission permission){
        permissionService.updatePermissonById(permission);
        return new ResultUtil<>().setData("修改成功");
    }

    @PostMapping("/admin/addPermisson")
    @ApiOperation(value = "添加权限节点")
    public Result addPermisson(Permission permission){
        permissionService.addPermisson(permission);
        return new ResultUtil<>().setData("添加成功");
    }
}
